import cv2

from utils.common import load_image, show_image, make_dirs  # 导入公共函数
from utils.config import exp5_orb_path, exp5_output_dir  # 导入输出路径

# 确保输出目录存在
make_dirs(exp5_output_dir)

# 加载图片并显示
image = load_image()

# 灰度化
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# 初始化FAST检测器
fast = cv2.FastFeatureDetector_create()
keypoints = fast.detect(gray_image, None)
# 初始化BRIEF描述符提取器
brief = cv2.xfeatures2d.BriefDescriptorExtractor_create()
keypoints, descriptors = brief.compute(gray_image, keypoints)

# 绘制关键点
img_with_keypoints = cv2.drawKeypoints(gray_image, keypoints, None, color=(255, 0, 0))

# 显示结果
show_image("FAST Keypoints with BRIEF Descriptors", img_with_keypoints)
# 保存结果
cv2.imwrite(exp5_orb_path, img_with_keypoints)
print(f"ORB结果已保存到：{exp5_orb_path}")